

#====================================================================
#
#		RESOURCE OBJECT
#
#====================================================================


#--------------------------------------------------------------------
Function New-Resource
{
	param
	(
		  [string]				$Root		= ""
		, [string]				$Path		= ""
		, [string]				$Name		= ""
		, [string]				$Mime		= ""
		, [byte[]]				$Data		= $null
		, [int]					$Size		= 0
	)
	[psobject] $obj = New-Object psobject
	Add-Member -InputObject $obj -Force -MemberType NoteProperty -Name Root		-Value $Root
	Add-Member -InputObject $obj -Force -MemberType NoteProperty -Name Path		-Value $Path
	Add-Member -InputObject $obj -Force -MemberType NoteProperty -Name Name		-Value $Name
	Add-Member -InputObject $obj -Force -MemberType NoteProperty -Name Mime		-Value $Mime
	Add-Member -InputObject $obj -Force -MemberType NoteProperty -Name Data		-Value $Data
	Add-Member -InputObject $obj -Force -MemberType NoteProperty -Name Size		-Value $Size
	return $obj
}


#--------------------------------------------------------------------
Function Read-Resource
{
	param
	(
		  [string]		$RootFolder
		, [string]		$ResourcePath
	)
	# Create ResourceItem and Set Paths
	$Resource = New-Resource
	$Resource.Root = $RootFolder
	$Resource.Path = Split-Path $ResourcePath -parent
	if( $Resource.Path -like "*\" )
	{
		$Resource.Path = $Resource.Path.SubString( 0, $Resource.Path.Length - 1 )
	}
	$Resource.Name = Split-Path $ResourcePath -leaf

	# Construct the full resource path.
	[string] $FullPath = $Resource.Root
	if( $Resource.Path -ne "" )
	{
		$FullPath += "\" + $Resource.Path
	}
	$FullPath += "\" + $Resource.Name

	# Get the resource.
	$Resource.Mime = Get-ItemMimeType $FullPath
	$Resource.Data = Get-Content -Path $FullPath -Encoding byte -TotalCount -1 -ReadCount 0
	$Resource.Size = $Resource.Data.Length
	
	# Return the resource.
	return $Resource
}


